<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    /*  // 循环输出1-50的数
     let i = 1
     while (i <= 50) {
       document.write(`这是第${i}个数<br>`)
       i++
     } */

    /* // 计算1-100总和并输出  
    let n = 1
    let sum = 0
    while (n <= 100) {
      sum = sum + n
      n++
    }
    document.write(`1-100总和为${sum}`) */

    /* // 计算1-100之间所有的偶数和
    let i = 1
    let sum = 0
    while (i <= 100) {
      if (i % 2 === 0) {
        sum = sum + i
      }
      i++
    }
    document.write(`1-100之间所有的偶数和为${sum}`) */

    // 计算1-100之间所有的奇数和
    let i = 1
    let sum = 0
    while (i <= 100) {
      if (i % 2 !== 0) {
        sum = sum + i
      }
      i++
    }
    document.write(`1-100之间所有的奇数和为${sum}`)
  </script>
</body>

</html>